<?php
$this->headLink()->appendStylesheet($this->baseUrl() . '/public/styles/colorbox/colorbox.css');
$this->headScript()->prependFile($this->baseUrl() . '/public/scripts/colorbox/jquery.colorbox-min.js');

$this->headLink()->appendStylesheet($this->baseUrl() . '/public/styles/datepicker/jquery.datepick.css');
$this->headScript()->prependFile($this->baseUrl() . '/public/scripts/datepicker/jquery.datepick.js');

$status = array('Pendiente', 'En Progreso', 'Pendiente con cliente', 'Cambios', 'Mas Información', 'Aprobado', 'Entregado');
?>
<article class="module width_full">
    <header><h3>Detalle de la orden</h3></header>

    <div style="display: none;">
        <img id="calImg" src="<?php echo $this->baseUrl() . '/public/img/calendar-blue.gif' ?>" alt="Popup" class="trigger">
    </div>

    <div class="module_content">
        <fieldset>
            <table>
                <tr>
                    <td><label>Codigo de Orden </label></td>
                    <td><span><?php echo $this->details->code ?></span></td>
                </tr>
                <tr>
                    <td><label>Titulo:</label></td>
                    <td><span><?php echo $this->details->title ?></span></td>
                </tr>
                <tr>
                    <td><label>Detalle de la orden:</label></td>
                    <td><span><?php echo $this->details->description ?></span></td>
                </tr>
<!--                <tr>
                    <td><label>Fecha de inicio</label></td>
                    <td><span><?php echo $this->details->create_date ?></span></td>
                </tr>
                <tr>
                    <td><label>Fecha limite</label></td>
                    <td><span><?php echo $this->details->end_date ?></span></td>
                </tr>-->
                <tr>
                    <td><label>Cambio Brief:</label></td>
                    <td><span><?php echo ($this->details->change_brief != '') ? $this->details->change_brief : 'No' ?></span></td>
                </tr>
                <tr>
                    <td><label>Trabajo Cambios</label></td>
                    <td><span><?php echo ($this->details->change_job != '') ? $this->details->change_job : 'No' ?></span></td>
                </tr>
<!--                <tr>
                    <td><label>Nueva Fecha Entrega</label></td>
                    <td><span><?php echo ($this->details->new_date_limit != '') ? $this->details->new_date_limit : 'No' ?></span></td>
                </tr>-->
                <tr>
                    <td><label>Archivos Adjuntos</label></td>
                    <td>
                        <table border="1">
                            <tr>
                                <td><b>Adjunto</b></td>
                                <td><b>Detalle</b></td>
                            </tr>
                            <?php foreach ($this->dataOrdenAttach as $attach): ?>
                                <tr>
                                    <td>
                                        <a href="<?php echo $this->baseUrl() ?>/attachment/index/download-attachment/id/<?php echo $attach->id ?>">
                                            <img width="16" src="<?php echo $this->baseUrl() ?>/public/styles/admin/images/icon_files/_<?php echo $attach->extension; ?>.png"/><?php echo $attach->name_original; ?>
                                        </a>
                                    </td>
                                    <td><?php echo $attach->description; ?></td>
                                </tr>

                                </div>
                            <?php endforeach; ?>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td><label>Agencias</label></td>
                    <td>
                        <?php
                        foreach ($this->dataOrdenDep as $dep) {
                            echo $dep->name . ', ';
                        }
                        ?>
                    </td>
                </tr>
            </table>
            <br/>       
            <table>
                <tr>
                    <td><label>Trabajos a revisar</label></td>
                    <td>
                        <table border="1">
                            <tr>
                                <td><b>Trabajo</b></td>
                                <td><b>Detalle</b></td>
                                <td><b>Fecha limite cliente</b></td>
                                <td><b>Fecha inicio agencia</b></td>
                                <td><b>Estado</b></td>
                                <td><b>Comentarios</b></td>
                            </tr>
                            <!-- *************** DATOS DE TODOS LOS DEMAS TRABAJOS DE LA ORDEN  **************  -->
                            <?php
                            foreach ($this->dataOrdenDepJob as $odj):
                                ?>
                                <tr>
                                    <td style="width: 80px"><?php echo $odj->name ?></td>
                                    <td style="width: 80px"><?php echo $odj->detail ?></td>
                                    <td>
                                        <?php 
                                            $nameDate = trim($odj->name);
                                            $nameDate = str_replace(' ', '_', $nameDate);
                                            $nameDate = str_replace('.', '_', $nameDate);
                                            $nameDate = str_replace(',', '_', $nameDate);
                                                    ?>
                                        <input type="text" name="dateClient<?php echo $nameDate ?>" id="dateClient<?php echo $nameDate ?>" style="width: 100px;"  value="<?php echo $odj->end_date_client ?>"/> 
                                        <script>
                                            $('#dateClient<?php echo $nameDate ?>').datepick({
                                                showOnFocus: false, 
                                                showTrigger: '#calImg',
                                                dateFormat: 'dd-mm-yyyy',
                                                onSelect: function(dates) {
                                                    $.ajax({
                                                        type: "GET",
                                                        url: "<?php echo $this->url(array('module' => 'orden', 'controller' => 'orden', 'action' => 'save-date-job')); ?>",
                                                        data: "dateClient="+$('#dateClient<?php echo $nameDate ?>').val()+"&idjob="+<?php echo $odj->id ?>+"&idorden="+<?php echo $this->details->id ?>+"&dateAgency="+$('#dateAgency<?php echo $nameDate ?>').val(),
                                                        success: function(datos){
                                                            alert("Fecha Guardada !!");
                                                        }
                                                    });
                                                }
                                            });
                                        </script>
                                    </td>
                                    <td>
                                        <input type="text" name="dateAgency<?php echo $nameDate ?>" id="dateAgency<?php echo $nameDate ?>" style="width: 100px;"  value="<?php echo $odj->begin_date_agency ?>"/> 
                                        <script>
                                            $('#dateAgency<?php echo $nameDate ?>').datepick({
                                                showOnFocus: false, 
                                                showTrigger: '#calImg',
                                                dateFormat: 'dd-mm-yyyy',
                                                onSelect: function(dates) {
                                                    $.ajax({
                                                        type: "GET",
                                                        url: "<?php echo $this->url(array('module' => 'orden', 'controller' => 'orden', 'action' => 'save-date-job')); ?>",
                                                        data: "dateAgency="+$('#dateAgency<?php echo $nameDate ?>').val()+"&idjob="+<?php echo $odj->id ?>+"&idorden="+<?php echo $this->details->id ?>+"&dateClient="+$('#dateClient<?php echo $nameDate ?>').val(),
                                                        success: function(datos){
                                                            alert("Fecha Guardada !!");
                                                        }
                                                    });
                                                }
                                            });
                                        </script>
                                    </td>
                                    <td><?php echo $status[$odj->status] ?></td>
                                    <td>
                                        <a class="inline" href="<?php echo $this->url(array('module' => 'orden', 'controller' => 'orden', 'action' => 'comment-job', 'id_orden' => $this->details->id, 'id_job' => $odj->id, 'name' => $odj->name)) ?>" title="Comentarios">
                                            <img src="<?php echo $this->baseUrl() ?>/public/styles/admin/images/comment.png" width="24"/> 
                                        </a>
                                    </td>
                                </tr>

                                <?php
                            endforeach;
                            ?>
                        </table>
                        <table>
                            <tr>
                                <td>
                                    <input type="button" id="ordencompleta" name="ordencompleta" value="Aprobar Orden"/>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </fieldset>
    </div>

    <footer></footer>
</article>


<script>
    $('#ordencompleta').click(function(){
        $.ajax({
            type: "GET",
            url: "<?php echo $this->url(array('module' => 'orden', 'controller' => 'orden', 'action' => 'orden-complet')); ?>",
            data: "idorden="+<?php echo $this->details->id ?>,
            success: function(datos){
                alert("Orden aprobada y finalizada  !!");
            }
        });
    });
    
    $(".inline").colorbox({height:'450px'});
</script>
